//方法一：使用中间变量交换

#include <stdio.h>

void reverse_array1(int arr[],int length)
{
    for (int i = 0; i < length / 2; i++) {
        int temp = arr[i];
        arr[i] = arr[length - 1 - i];
        arr[length - 1 - i] = temp;
    }
}

//方法二： 使用指针进行交换
void reverse_array2(int arr[], int length) {
    int *p = arr, *q = arr + length - 1;
    while (p < q) {
        int temp = *p;
        *p = *q;
        *q = temp;
        p++;
        q--;
    }
}

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    int length = sizeof(arr) / sizeof(arr[0]);

    //reverse_array1(arr, length);
    reverse_array2(arr,length);
    

    for (int i = 0; i < length; i++) {
        printf("%d ", arr[i]);
    }

    return 0;
}

